<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>收货地址</title>
<link rel="stylesheet" href="<?php echo TEMPLATE_SITE_URL;?>/css/style.css" type="text/css">
<script type="text/javascript" src="<?php echo RESOURCE_SITE_URL;?>/js/zepto.js" charset="utf-8"></script>
</head>
<body style="background:#eee">
<div id="section_login">
<section>
<header>
	<div class="header-box">
		<a id="J_cancel" href="javascript:history.go(-1);" class="new-btn new-btn-orange new-btn-back">
        	<b class="caret"></b>返回
		</a>添加收货地址
	</div>
</header>
	<!--登录-->
	<div id="dp_banner"></div>
	<form id="J_login_form">
		<div class="login-frame verification-login">
			<ul>
				<li>
					<p class="input-box">
						<input name="name" class="default" placeholder="收件人姓名" type="text">
					</p>
				</li>
				<li>
					<p class="input-box">
						<input name="tele" class="default" placeholder="收件人电话" type="number">
					</p>
				</li>
				<li>
					<p class="input-box" id="quyuxinxi">
						<span class="pid">所在地区&nbsp;&nbsp;
							<select name="pid">
								<option>请选择...</option>
								<?php if(!empty($output['prov'])){?>
								<?php foreach($output['prov'] as $prov){?>
								<option value="<?php echo $prov['region_code'];?>"><?php echo $prov['region_name'];?></option>
								<?php }?>
								<?php }?>
							</select>
						</span>
						<span class="cid"></span>
						<span class="did"></span>
					</p>
				</li>
				<li>
					<p class="input-box">
						<input name="address" class="default" placeholder="详细地址" type="text">
					</p>
				</li>
			</ul>
			<p id="account_err" class="err-holder"></p>
			<div class="login-btn">
				<input type="hidden" name="order_id" value="<?php echo $_GET['order_id']?>">
				<input type="hidden" name="auction_id" value="<?php echo $_GET['auction_id']?>">
				<input id="J_submit" value="保存" class="icon-btn b-2 margin-lt-2" type="button">
			</div>
		</div>
	</form>
</section>
</div>

<script type="text/javascript">
$(function(){

	$('select[name="pid"]').change(function(){
		var pid = $(this).val();
		$.ajax({
			type:'get',
			url:'index.php?act=payment&op=getcityson',
			data:{pid:pid},
			dataType:'html',
			success:function(html){
				$('.cid').html(html);

				$('select[name="cid"]').change(function(){

					var cid = $(this).val();
					
					$.ajax({
						type:'get',
						url:'index.php?act=payment&op=getareason',
						data:{cid:cid},
						dataType:'html',
						success:function(html){
							$('.did').html(html);
						}
					});
				});
			}	
		});
	});
	
	$('#J_submit').on('click',function(){
		var order_id = $('input[name=order_id]').val();
		var auction_id = $('input[name=auction_id]').val();
		var name = $('input[name=name]').val();
		var tele = $('input[name=tele]').val();
		var address = $('input[name=address]').val();
		var pid = $("select[name=pid]").val();
		var cid = $("select[name=cid]").val();
		var did = $("select[name=did]").val();

		if(did=='undefined'){
			did = '';
		}
		
		$.ajax({
			type:'post',
			url:'index.php?act=payment&op=addressadd',
			data:{name:name,tele:tele,address:address,pid:pid,cid:cid,did:did},
			dataType:'json',
			success:function(res){
				if(res.state){
					if(auction_id!=''){
						location.href = 'index.php?act=payment&op=addresslist&auction_id='+auction_id;
					}else{
						location.href = 'index.php?act=payment&op=addresslist&order_id='+order_id;
					}	
					return false;
				}
				return false;
			}
		});
	});
});
</script>
</body>
</html>